package com.hpu.parser;

import com.hpu.bean.News;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class NewsParser {
	
	public List<News> parse(String parseString){
		List<News> news=new ArrayList<News>();
		try {
			JSONObject object=new JSONObject(parseString);
			String prefix=object.getString("prefix");
			JSONArray array=object.getJSONArray("data");
			
			for(int i=0;i<array.length();i++){
				JSONObject object2=array.getJSONObject(i);
				news.add(new News(prefix+object2.getString("id"), object2.getString("name"),object2.getString("time")));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return news;
	}
}
